<template>
        <el-scrollbar style="height:100%;">
            <div class="container p-40">
                <div>
                <el-form ref="refForm" v-loading="loading" :rules="rules" :model="basicForm"
                    :disabled="window||basicForm.contractAuditState===2||$route.query.isdetail" label-width="100px">
                    <p class="f-17 m-b-20">出租人信息</p>
                    <el-row :gutter="40">
                    <el-col :span="8">
                        <el-form-item label="出租人" prop="fkLessorId">
                        <el-select placeholder="请选择" v-model="basicForm.fkLessorId">
                            <el-option v-for="item in lessor" :key="item.pkBasicdataId" :value="item.pkBasicdataId"
                            :label="item.itemName"></el-option>
                        </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="楼宇名称" prop="fkBuildingId">
                        <el-select placeholder="请选择" @change="changeBuilding" v-model="basicForm.fkBuildingId">
                            <el-option v-for="item in buildingData" :key="item.pkBuildingId" :value="item.pkBuildingId" :label="item.buildingName">
                            </el-option>
                        </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="地址信息">
                        <el-input :value="localAddress" :disabled="true" placeholder="地址信息"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="房间号" prop="fkRoomId">
                        <el-select placeholder="请选择" @change="selRoom" v-model="basicForm.fkRoomId">
                            <el-option v-for="item in roomData" :key="item.pkRoomId" :value="item.pkRoomId" :label="item.houseNumber">
                                 <span style="float: left">{{ item.houseNumber }}</span>
                                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.status }}</span>
                            </el-option>
                        </el-select>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="8">
                        <el-form-item label="房间状态">
                        <el-input :disabled="true" placeholder="房间状态" :value="StatusName">
                        </el-input>
                        </el-form-item>
                    </el-col> -->
                    </el-row>
                    <p class="f-17 m-b-20">承租人信息</p>
                    <!-- 固定头部 -->
                    <el-row :gutter="40">
                    <el-col :span="8">
                        <el-form-item label="租户类型" prop="tenantType">
                        <el-radio-group v-model="basicForm.tenantType">
                            <el-radio label="0">个人</el-radio>
                            <el-radio label="1">企业</el-radio>
                        </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="合同开始时间" label-width="120px" prop="contractStartTime">
                        <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="date" placeholder="选择起始日期"
                            :picker-options="maxDatePicker" v-model="basicForm.contractStartTime" style="width: 100%"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="合同结束时间" label-width="120px" prop="contractEndTime">
                        <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="date" placeholder="选择结束日期"
                            :picker-options="maxDatePicker" v-model="basicForm.contractEndTime" style="width: 100%"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    </el-row>
                    <!-- 动态尾部  0 个人-->
                    <template v-if="basicForm.tenantType==='0'">
                    <el-row :gutter="40">
                        <el-col :span="8">
                        <el-form-item label="开票方式" prop="invoiceMethod">
                            <el-select v-model="basicForm.invoiceMethod">
                            <el-option label="线上开票" value="0"></el-option>
                            <el-option label="线下开票" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="手机号" prop="contactPhone">
                            <el-input type="number" placeholder="请输入手机号" v-model="basicForm.contactPhone"></el-input>
                        </el-form-item>
                        </el-col>

                        <el-col :span="8">
                        <el-form-item label="电子邮箱">
                            <el-input placeholder="请输入电子邮箱" v-model="basicForm.email"></el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="月租金" prop="monthlyRent">
                            <el-input type="number" placeholder="请输入月租金" v-model="basicForm.monthlyRent"></el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="押金" prop="deposit">
                            <el-input type="number" placeholder="请输入押金" v-model="basicForm.deposit">
                            <template slot="suffix">人民币</template>
                            </el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="承租人" prop="tenantName">
                            <el-input placeholder="请输入承租人" v-model="basicForm.tenantName"></el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="身份证号" prop="idcardNumber">
                            <el-input placeholder="请输入身份证号" v-model="basicForm.idcardNumber"></el-input>
                        </el-form-item>
                        </el-col>
                    </el-row>
                    </template>
                    <!-- 其他 （1）企业 -->
                    <template v-else>
                    <el-row :gutter="40">
                        <el-col :span="8">
                        <el-form-item label="开票方式" prop="invoiceMethod">
                            <el-select v-model="basicForm.invoiceMethod">
                            <el-option label="线上开票" value="0"></el-option>
                            <el-option label="线下开票" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="公司地址">
                            <el-input placeholder="请输入公司地址" v-model="basicForm.address"></el-input>
                        </el-form-item>
                        </el-col>

                        <el-col :span="8">
                        <el-form-item label="联系人" prop="contacts">
                            <el-input placeholder="请输入联系人" v-model="basicForm.contacts"></el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="手机号" prop="contactPhone">
                            <el-input type="number" placeholder="请输入手机号" v-model="basicForm.contactPhone"></el-input>
                        </el-form-item>
                        </el-col>

                        <el-col :span="8">
                        <el-form-item label="电子邮箱" prop="email">
                            <el-input placeholder="请输入电子邮箱" v-model="basicForm.email"></el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="月租金" prop="monthlyRent">
                            <el-input placeholder="￥请输入" v-model="basicForm.monthlyRent"></el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="押金" prop="deposit">
                            <el-input type="number" placeholder="请输入押金" v-model="basicForm.deposit"></el-input>
                        </el-form-item>
                        </el-col>

                        <el-col :span="8">
                        <el-form-item label="承租人" prop="tenantName">
                            <el-input placeholder="请输入承租人" v-model="basicForm.tenantName"></el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="法人" prop="enterpriseLegalPerson">
                            <el-input placeholder="请输入法人" v-model="basicForm.enterpriseLegalPerson"></el-input>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="统一信用代码" prop="idcardNumber">
                            <el-input placeholder="请输入统一信用代码" v-model="basicForm.idcardNumber"></el-input>
                        </el-form-item>
                        </el-col>

                        <el-col :span="24">
                        <!-- prop="fkUpPhotoId" -->
                        <el-form-item label="营业执照" prop="fkUpPhotoId">
                            <up-img v-model="basicForm.fkUpPhotoId" imgWidth="150px" imgHeight="100px"
                            btnImg="/static/images/title-deed-icon.png" ref="UpPhotoIdImg"></up-img>
                        </el-form-item>
                        </el-col>
                    </el-row>
                    </template>

                    <p class="f-17 m-b-20">其他信息</p>
                    <el-row :gutter="40">
                    <el-col :span="8">
                        <el-form-item label="合同编号" prop="contractNumber">
                        <el-input placeholder="请输入合同编号" v-model="basicForm.contractNumber"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="备案登记号" prop="recordRegistrationNumber">
                        <el-input v-model="basicForm.recordRegistrationNumber" placeholder="请输入备案登记号"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="合同用途" prop="fkContractPurposeId">
                        <el-select placeholder="请选择" v-model="basicForm.fkContractPurposeId">
                            <el-option v-for="item in contractPurpose" :key="item.pkBasicdataId" :value="item.pkBasicdataId"
                            :label="item.itemName"></el-option>
                        </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="合同原件" prop="fkContractOriginalId">
                        <up-img v-model="basicForm.fkContractOriginalId" imgWidth="150px" imgHeight="100px"
                            :imgLength="(window||basicForm.contractAuditState===2||$route.query.isdetail)?0:999"
                            :close="!(window||basicForm.contractAuditState===2||$route.query.isdetail)"
                            btnImg="/static/images/title-deed-icon.png" ref="uploadImg"></up-img>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="出租方式" prop="fkRentalModeId">
                        <el-select placeholder="请选择" v-model="basicForm.fkRentalModeId">
                            <!-- :label="item.itemName" -->
                            <el-option v-for="item in rentalMode" :key="item.pkBasicdataId" :value="item.pkBasicdataId"
                            :label="item.itemName">
                            </el-option>
                        </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="备注及其他">
                        <el-input type="textarea" show-word-limit maxlength="400" :rows="3" placeholder="请输入内容"
                            v-model="basicForm.remarks"></el-input>
                        </el-form-item>
                    </el-col>
                    </el-row>
                </el-form>
                <!--动态 核实 退租 窗体小表单-->
                <el-form class="window-form" ref="basicForm" :rules="rules" :model="basicForm" label-width="100px">
                    <template v-if="window&&!state">
                    <p class="f-17 m-b-20">退租操作</p>
                    <el-row>
                        <el-col :span="8">
                        <el-form-item label="实际结束日期" prop="contractActualEndTime">
                            <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" type="date" placeholder="选择起始日期"
                            v-model="basicForm.contractActualEndTime" style="width: 100%"></el-date-picker>
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="退租原因" prop="causeDescription">
                            <el-input placeholder="请输入" v-model="basicForm.causeDescription" />
                        </el-form-item>
                        </el-col>
                        <el-col :span="8">
                        <el-form-item label="实退金额" prop="actualRefund">
                            <el-input type="number" placeholder="请输入" v-model="basicForm.actualRefund"></el-input>
                        </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                        <el-form-item label="退款说明" prop="refundInstructions">
                            <el-input type="textarea" :disabled="false" :rows="3" show-word-limit maxlength="200"
                            placeholder="请输入内容" v-model="basicForm.refundInstructions"></el-input>
                        </el-form-item>
                        </el-col>
                    </el-row>
                    </template>
                    <template v-else-if="window">
                    <p class="f-17 m-b-20">审核操作</p>
                    <el-row :gutter="40">
                        <el-col :span="12">
                        <el-form-item label="审核操作" prop="auditOpinion">
                            <el-radio-group v-model="basicForm.auditOpinion">
                            <el-radio label="1">审核不通过</el-radio>
                            <el-radio label="2">审核通过</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        </el-col>
                        <el-col :span="24">
                        <el-form-item label="原因说明" prop="causeDescription">
                            <el-input type="textarea" show-word-limit :maxlength="400" :disabled="basicForm.auditOpinion === '2'"
                            :rows="3" placeholder="请输入内容" v-model="basicForm.causeDescription"></el-input>
                        </el-form-item>
                        </el-col>
                    </el-row>
                    </template>
                </el-form>
                <!-- 审核未通过 或者 等于退租-->
                <el-row v-if="!(basicForm.contractAuditState===2&&state!=0)&&!($route.query.isdetail)" justify="center" style="margin-top: 0.2rem">
                    <el-col :span="4" :offset="10">
                    <el-button type="primary" @click="submitForm" :loading="hasSubmit">确定</el-button>
                    <el-button @click="close">取消</el-button>
                    </el-col>
                </el-row>
                <el-row v-if="$route.query.isdetail" justify="center" style="margin-top: 0.2rem">
                    <el-col :span="4" :offset="10">
                    <el-button type="info" @click="close">返回</el-button>
                    </el-col>
                </el-row>
                <!-- 审核表格 有审核记录就展现 -->
                <el-row v-if="basicForm.auditRecods&&basicForm.auditRecods.length">
                    <el-col :span="24">
                    <el-table class="bottom-table" :data="basicForm.auditRecods">
                        <el-table-column prop="reviewerName" label="审核人">
                        </el-table-column>
                        <el-table-column prop="auditTime" label="审核时间">
                        <template slot-scope="{row}">
                            {{row.auditTime | timeFormatFilter("yyyy-mm-dd")}}
                        </template>
                        </el-table-column>
                        <el-table-column prop="auditOpinion" label="审核意见">
                        <template slot-scope="scope">
                            {{scope.row.auditOpinion |auditOpinionFilter}}
                        </template>
                        </el-table-column>
                        <el-table-column prop="causeDescription" label="原因说明">
                        </el-table-column>
                    </el-table>
                    </el-col>
                    <!--  -->
                </el-row>
                <!-- 退租表格 合同状态已终止则显示 -->
                <el-row v-if="basicForm.contractState=='2'">
                    <el-col :span="24">
                    <el-table class="bottom-table" :data="[basicForm]">
                        <el-table-column prop="tenantName" label="承租人">
                        </el-table-column>
                        <el-table-column prop="contractActualEndTime" label="合同终止时间">
                        <template slot-scope="scope">
                            {{scope.row.contractActualEndTime | timeFormatFilter("yyyy-mm-dd")}}
                        </template>
                        </el-table-column>
                        <el-table-column prop="actualRefund" label="实退款金额">
                        </el-table-column>
                        <el-table-column prop="refundInstructions" label="退款说明">
                        </el-table-column>
                    </el-table>
                    </el-col>
                </el-row>
                </div>
            </div>
        </el-scrollbar>
</template>

<script>
  import {
    addContract,
    getContractById,
    updateContract,
    surrender,
    reviewContract,
  } from "@/api/operations/contract/contract.js";
  import {
    getBuildingName,
    getAllAreaNumber,
  } from "@/api/house/building/building.js";
  import { getOneAll, selectNameToId, UploadImage } from '@/api/common/common'
  import upImg from '@/components/upImg'
  export default {
    components: {
      upImg
    },
    props: [
      "window", //是否window bool
      "state", //窗口打开时有效 0.退租 1.审核 number
      "contractId", //合同ID
    ],
    watch: {
      contractId() {
        this.loadDetail(this.contractId);
      },
      'basicForm.auditOpinion'() {
        //核审通过
        if (this.basicForm.auditOpinion === '2') {
          this.basicForm.causeDescription = '审核通过';
        } else {
          this.basicForm.causeDescription = '';
        }
      },
      'basicForm.tenantType'() {
        this.$refs['refForm'].clearValidate();
        if (this.basicForm.tenantType === '1') {
          this.rules.idcardNumber = [{
            required: true,
            message: "请输入统一信用代码",
          }]
        } else {
          this.rules.idcardNumber = [{
            required: true,
            message: "请输入身份证号码",
          }]
        }
      }
    },
    computed: {
      fkRoomEndDate(){
          let fkRoom = this.roomData.filter(v=>this.basicForm.fkRoomId==v.pkRoomId);
          return fkRoom.length&&fkRoom[0].endTime;
      }
    },
    data() {
      return {
        hasSubmit: false,
        //是否修改
        isUpdate: false,
        loading: false,
        //0,个人 1,企业 选择用户
        userType: 0,
        //楼宇下拉
        buildingData: [],
        localAddress: "",
        roomData: [],
        building: {},
        lessor: [],
        contractPurpose: [],
        roomState: [],
        rentalMode: [],
        //全部FROM
        basicForm: {
          oldRoomId: null, //旧房间ID
          fkUpPhotoId: null,
          fkContractOriginalId: "",
          createdBy: 1,
          lastUpdatedBy: 1,
          fkRoomId: null,
          tenantType: "0",
        },
        maxDatePicker:{
            shortcuts:[{
                text:"房间空置时间",
                onClick:(picker)=>{
                    if(this.fkRoomEndDate){
                        let endDate = new Date(this.fkRoomEndDate);
                        picker.$emit('pick', new Date(endDate.setDate(endDate.getDate()+1)));
                    }else{
                        picker.$emit('pick', new Date());
                    }
                }
            }],
            disabledDate:(time)=>{
                if(this.fkRoomEndDate){
                    let endDate = new Date(this.fkRoomEndDate);
                    endDate = new Date(endDate.setDate(endDate.getDate()+1));
                    return time.getTime() < endDate.getTime() ;
                }else{ 
                    return false;
                }
            }
        },
        rules: {
          fkRentalModeId: [
            {
              required: true,
              message: "请选择出租方式",
            }
          ],
          invoiceMethod: [
            {
              required: true,
              message: "请选择开票方式",
            }
          ],
          fkUpPhotoId: [
            {
              required: true,
              message: "请上传营业执照",
            }
          ],
          fkRoomStatusId: [
            {
              required: true,
              message: "请选择房间状态",
            }
          ],
          fkContractOriginalId: [
            {
              required: true,
              message: "请上传合同原件",
            }
          ],
          fkLessorId: [
            {
              required: true,
              message: "请选择出租人",
            },
          ],
          fkBuildingId: [
            {
              required: true,
              message: "请选择楼宇",
            },
          ],
          fkRoomId: [
            {
              required: true,
              message: "请选择房间号",
              trigger: "change",
            },
          ],
          tenantType: [
            {
              required: true,
              message: "请选择租户类型",
            },
          ],
          contractStartTime: [
            {
              required: true,
              message: "请选择开始日期",
            },
          ],
          contractEndTime: [
            {
              required: true,
              message: "请选择结束日期",
            },
          ],
          contactPhone: [
            {
              required: true,
              message: "请输入手机号",
            },
            { validator: this.$rules.phoneNumber,trigger:"blur" }
          ],
          email: [
            {
              required: true,
              message: "请输入邮箱号",
            },
            { validator: this.$rules.emailValue ,trigger:"blur"}
          ],
          monthlyRent: [
            {
              required: true,
              message: "请输入月租金",
            },
            {validator: this.$rules.PriceNumber,trigger:"blur" }

          ],
          deposit: [
            {
              required: true,
              message: "请输入押金",
            },
            { validator: this.$rules.PriceNumber ,trigger:"blur"}

          ],
          tenantName: [
            {
              required: true,
              message: "请输入承租人",
            },
          ],
          idcardNumber: [
            {
              required: true,
              message: "请输入身份证号",
            },
            { validator: this.$rules.idCard , trigger:"blur" }
          ],
          enterpriseLegalPerson: [
            {
              required: true,
              message: "请输入法人名称",
            },
          ],
          contractNumber: [
            {
              required: true,
              message: "请输入合同编号",
            },
          ],
          recordRegistrationNumber: [
            {
              required: true,
              message: "请输入备案登记号",
            },
          ],
          fkContractPurposeId: [
            {
              required: true,
              message: "请选择合同用途",
            },
          ],
          contacts: [
            {
              required: true,
              message: "请输入联系人",
              trigger: "blur"
            },
          ],
          contractActualEndTime: [
            {
              required: true,
              message: "请选择合同终止时间",
              trigger: "blur"
            },
          ],
          auditOpinion: [
            {
              required: true,
              message: "请选择审核操作",
            },
          ],
          actualRefund: [
            {
              required: true,
              message: "请输入实际退款金额",
              trigger: "blur"
            },
          ],
          causeDescription: [
            {
              required: true,
              message: "请输入原因说明",
              trigger: "blur"
            },
          ],
          refundInstructions: [
            {
              required: true,
              message: "请输入退款说明",
              trigger: "blur"
            },
          ],
        },
      };
    },
    methods: {
        selRoom(){
            if(this.basicForm.contractStartTime && this.maxDatePicker.disabledDate(this.basicForm.contractStartTime)){
                this.basicForm.contractStartTime = null;
            }
            if(this.basicForm.contractEndTime && this.maxDatePicker.disabledDate(this.basicForm.contractEndTime)){
                this.basicForm.contractEndTime = null;
            }
        },
        submitForm() {
            //不是窗口 == no 退租 no 审核时
            if (!this.window) {
            this.$refs["refForm"].validate((valid) => {
                if (valid) {
                this.hasSubmit = true;
                new Promise((resolve, reject) => {
                    if (this.$refs['UpPhotoIdImg'] === undefined) {
                        resolve();
                    } else {
                        this.$refs['UpPhotoIdImg'].submit().then(res => {
                            resolve();
                        }).catch(_=>{
                            reject();
                        });
                    }
                }).then(() => {
                    this.$refs['uploadImg'].submit().then(res => {
                        if (!this.isUpdate) {
                        addContract(this.basicForm).then((result) => {
                            if (result.code === 10000) {
                            this.$message.success(result.msg);
                            this.close();
                            }
                        }).finally(_ => {
                            this.hasSubmit = false;
                        });
                        } else {
                        updateContract(this.basicForm).then((result) => {
                            if (result.code === 10000) {
                            this.$message.success(result.msg);
                            this.close();
                            }
                        }).finally(_ => {
                            this.hasSubmit = false;
                        });
                        }
                    }).catch(_=>{
                        this.hasSubmit = true;
                    });
                });
                };
            });
            } else if (this.state === 1) {
            this.$refs["basicForm"].validate((valid) => {
                if (!valid) return false;
                this.hasSubmit = true;
                //审核
                let obj = {
                auditOpinion: this.basicForm.auditOpinion,
                causeDescription: this.basicForm.causeDescription,
                fkContractId: this.basicForm.pkContractId,
                };
                reviewContract(obj).then((res) => {
                if (res.code === 10000) {
                    this.$message.success(res.msg);
                    this.$emit("reLoad");
                    this.close();
                }
                }).finally(_ => {
                this.hasSubmit = false;
                });
            });
            } else if (this.state === 0) {
            this.$refs["basicForm"].validate((valid) => {
                if (!valid) return false;
                this.hasSubmit = true;
                //退租
                surrender(this.basicForm).then((res) => {
                if (res.code === 10000) {
                    this.$message.success(res.msg);
                    this.$emit("reLoad");
                    this.close();
                }
                }).finally(_ => {
                this.hasSubmit = false;
                });
            });
            }
        },
        close() {
            if (!this.window === true) {
            this.$router.push("/contract/list");


            // let rex = this.$route.matched[this.$route.matched.length - 1].regex;
            // this.$store.commit("delTabs", rex);
            } else {
            this.$store.commit("changeWindow", {
                name: "contractEditWindow",
                val: false,
            });
            }
        },
        loadDetail(id) {
            getContractById(id).then((result) => {
            this.basicForm = result.data;
            this.basicForm.oldRoomId = this.basicForm.fkRoomId;
            this.loading = false;
            this.getRoom();
            });
        },
        getBuiling() {
            getBuildingName().then((res) => {
            this.buildingData = res.data;
            });
        },
        changeBuilding() {
            // alert(this.basicForm.fkRoomId);
            this.basicForm.fkRoomId = null;
            this.getRoom();
        },
        getRoom() {
            getAllAreaNumber(this.basicForm.fkBuildingId).then((res) => {
            this.roomData = res.data.roomList;
            this.localAddress = res.data.province + res.data.city + res.data.area + res.data.street;
            });
        }
    },
    mounted() {
      getOneAll(selectNameToId("rentalMode")).then(res => {
        this.rentalMode = res.data;
      });
      getOneAll(selectNameToId("lessor")).then(res => {
        this.lessor = res.data;
      });
      getOneAll(selectNameToId("roomState")).then(res => {
        this.roomState = res.data;
      });
      getOneAll(selectNameToId("contractPurpose")).then(res => {
        this.contractPurpose = res.data;
      });
      this.getBuiling();
      if (this.$route.params.id) {
        this.isUpdate = true;
        this.loading = true;
        this.loadDetail(this.$route.params.id);
      } else if (this.window) {
        if (!this.contractId) {
          this.$message.warning("未找到相应的合同");
          this.close();
        } else {
          this.loadDetail(this.contractId);
        }
      }
    },
  };
</script>
